package util.texture.textureGenerators;

import util.Color4F;
import util.Vec2F;

public class InverseRSquaredTextureGenerator extends BaseFloatTextureDataGenerator
{
	private final float divisionFactor;
	private final float numerator;
	private final float subtractionConstant;
	public InverseRSquaredTextureGenerator(float amplitude,float divisionFactor)
	{
		float radius = 1.0f;
		this.divisionFactor = divisionFactor;
		this.numerator = (radius*radius + divisionFactor) * amplitude * divisionFactor / (radius*radius);
		this.subtractionConstant = numerator / (divisionFactor + radius * radius);
	}
	@Override
	protected Color4F texelValue(Vec2F location)
	{
		float brightness;		
		float denominator = divisionFactor + location.mag2();
		brightness = (numerator / denominator) - subtractionConstant;
		if(brightness < 0.0f)
			brightness = 0.0f;

		return new Color4F(brightness,0.0f,0.0f,1.0f);
	}

}
